package cn.tedu.logistics.controller;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.tedu.logistics.bean.Shop;
import cn.tedu.logistics.service.ShopService;


@Controller
public class ShopController {
	@Autowired
	private ShopService service;
	
	//查询所有门店
	@RequestMapping("/shop")
	public String listShop(Model modle) {
		List<Shop> list=service.findAllShop();
		modle.addAttribute("list", list);
		return "shop";
	}
	
	//添加门店页面
	@RequestMapping("/toAddShop")
	public String toAddShop() {
		return "addShop";
	}
	
	//添加门店
	@RequestMapping("/addShop")
	public String addShop(String shopId,String shopName,String shopPhone,Date createTime,Date updateTime) {
		Shop shop = new Shop();
		shop.setShopId(shopId)
			.setShopName(shopName)
			.setShopPhone(shopPhone)
			.setCreateTime(new Date())
			.setUpdateTime(new Date());
		service.addShop(shop);
		return "redirect:shop";
	}
	
	//删除门店
	@RequestMapping("/delShop")
	public String delShop(String shopId) {
		service.delShop(shopId);
		return "redirect:shop";
	}
	
	//更新门店
	@RequestMapping("/toUpdShop")
	public String toUpdShop(String shopId,Model modle) {
		Shop shop=service.selectById(shopId);
		modle.addAttribute("shop", shop);
		return "updShop";
	}
	
	//更新门店
	@RequestMapping("/updShop")
	public String updReader(String shopId,String shopName,String shopPhone,Date createTime,Date updateTime) {
		Shop shop=new Shop();
		shop.setShopId(shopId)
			.setShopName(shopName)
			.setShopPhone(shopPhone)
			.setCreateTime(createTime)
			.setUpdateTime(new Date());
		service.updateShop(shop);
		return "redirect:shop";
	}
	
	@RequestMapping("/checkShopId")
	@ResponseBody
	public int checkCarId(String shopId) {
		return service.checkShopId(shopId);
	}
	
}
